<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>Animated Fool's Mate</title>
  <meta name="description" content="Fool's Mate implemented with CSS Grid and animated grid rows and grid columns.">
  <meta name="author" content="Chen Hui Jing">
  <style>@font-face{font-family:Emoji;src:local("Apple Color Emoji"),local("Segoe UI Emoji"),local("Segoe UI Symbol"),local("Noto Color Emoji")}body{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;text-align:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center}p{line-height:1.4;max-width:48em}.board{background-color:#eee;background-image:-webkit-linear-gradient(45deg,#d18b47 25%,transparent 25%,transparent 75%,#d18b47 75%,#d18b47),-webkit-linear-gradient(45deg,#d18b47 25%,transparent 25%,transparent 75%,#d18b47 75%,#d18b47);background-image:-o-linear-gradient(45deg,#d18b47 25%,transparent 25%,transparent 75%,#d18b47 75%,#d18b47),-o-linear-gradient(45deg,#d18b47 25%,transparent 25%,transparent 75%,#d18b47 75%,#d18b47);background-image:linear-gradient(45deg,#d18b47 25%,transparent 25%,transparent 75%,#d18b47 75%,#d18b47),linear-gradient(45deg,#d18b47 25%,transparent 25%,transparent 75%,#d18b47 75%,#d18b47);background-size:24vmin 24vmin;background-position:0 0,12vmin 12vmin;width:96vmin;height:96vmin;margin:auto}.piece{font-size:6vmin;font-family:Emoji}main{position:relative;height:96vmin;width:96vmin}.grid{display:-ms-grid;display:grid;position:absolute}.board{-ms-grid-columns:(12vmin)[8];grid-template-columns:repeat(8,12vmin);-ms-grid-rows:(12vmin)[8];grid-template-rows:repeat(8,12vmin)}.board>:nth-child(1){-ms-grid-row:1;-ms-grid-column:1}.board>:nth-child(2){-ms-grid-row:1;-ms-grid-column:2}.board>:nth-child(3){-ms-grid-row:1;-ms-grid-column:3}.board>:nth-child(4){-ms-grid-row:1;-ms-grid-column:4}.board>:nth-child(5){-ms-grid-row:1;-ms-grid-column:5}.board>:nth-child(6){-ms-grid-row:1;-ms-grid-column:6}.board>:nth-child(7){-ms-grid-row:1;-ms-grid-column:7}.board>:nth-child(8){-ms-grid-row:1;-ms-grid-column:8}.board>:nth-child(9){-ms-grid-row:2;-ms-grid-column:1}.board>:nth-child(10){-ms-grid-row:2;-ms-grid-column:2}.board>:nth-child(11){-ms-grid-row:2;-ms-grid-column:3}.board>:nth-child(12){-ms-grid-row:2;-ms-grid-column:4}.board>:nth-child(13){-ms-grid-row:2;-ms-grid-column:5}.board>:nth-child(14){-ms-grid-row:2;-ms-grid-column:6}.board>:nth-child(15){-ms-grid-row:2;-ms-grid-column:7}.board>:nth-child(16){-ms-grid-row:2;-ms-grid-column:8}.board>:nth-child(17){-ms-grid-row:3;-ms-grid-column:1}.board>:nth-child(18){-ms-grid-row:3;-ms-grid-column:2}.board>:nth-child(19){-ms-grid-row:3;-ms-grid-column:3}.board>:nth-child(20){-ms-grid-row:3;-ms-grid-column:4}.board>:nth-child(21){-ms-grid-row:3;-ms-grid-column:5}.board>:nth-child(22){-ms-grid-row:3;-ms-grid-column:6}.board>:nth-child(23){-ms-grid-row:3;-ms-grid-column:7}.board>:nth-child(24){-ms-grid-row:3;-ms-grid-column:8}.board>:nth-child(25){-ms-grid-row:4;-ms-grid-column:1}.board>:nth-child(26){-ms-grid-row:4;-ms-grid-column:2}.board>:nth-child(27){-ms-grid-row:4;-ms-grid-column:3}.board>:nth-child(28){-ms-grid-row:4;-ms-grid-column:4}.board>:nth-child(29){-ms-grid-row:4;-ms-grid-column:5}.board>:nth-child(30){-ms-grid-row:4;-ms-grid-column:6}.board>:nth-child(31){-ms-grid-row:4;-ms-grid-column:7}.board>:nth-child(32){-ms-grid-row:4;-ms-grid-column:8}.board>:nth-child(33){-ms-grid-row:5;-ms-grid-column:1}.board>:nth-child(34){-ms-grid-row:5;-ms-grid-column:2}.board>:nth-child(35){-ms-grid-row:5;-ms-grid-column:3}.board>:nth-child(36){-ms-grid-row:5;-ms-grid-column:4}.board>:nth-child(37){-ms-grid-row:5;-ms-grid-column:5}.board>:nth-child(38){-ms-grid-row:5;-ms-grid-column:6}.board>:nth-child(39){-ms-grid-row:5;-ms-grid-column:7}.board>:nth-child(40){-ms-grid-row:5;-ms-grid-column:8}.board>:nth-child(41){-ms-grid-row:6;-ms-grid-column:1}.board>:nth-child(42){-ms-grid-row:6;-ms-grid-column:2}.board>:nth-child(43){-ms-grid-row:6;-ms-grid-column:3}.board>:nth-child(44){-ms-grid-row:6;-ms-grid-column:4}.board>:nth-child(45){-ms-grid-row:6;-ms-grid-column:5}.board>:nth-child(46){-ms-grid-row:6;-ms-grid-column:6}.board>:nth-child(47){-ms-grid-row:6;-ms-grid-column:7}.board>:nth-child(48){-ms-grid-row:6;-ms-grid-column:8}.board>:nth-child(49){-ms-grid-row:7;-ms-grid-column:1}.board>:nth-child(50){-ms-grid-row:7;-ms-grid-column:2}.board>:nth-child(51){-ms-grid-row:7;-ms-grid-column:3}.board>:nth-child(52){-ms-grid-row:7;-ms-grid-column:4}.board>:nth-child(53){-ms-grid-row:7;-ms-grid-column:5}.board>:nth-child(54){-ms-grid-row:7;-ms-grid-column:6}.board>:nth-child(55){-ms-grid-row:7;-ms-grid-column:7}.board>:nth-child(56){-ms-grid-row:7;-ms-grid-column:8}.board>:nth-child(57){-ms-grid-row:8;-ms-grid-column:1}.board>:nth-child(58){-ms-grid-row:8;-ms-grid-column:2}.board>:nth-child(59){-ms-grid-row:8;-ms-grid-column:3}.board>:nth-child(60){-ms-grid-row:8;-ms-grid-column:4}.board>:nth-child(61){-ms-grid-row:8;-ms-grid-column:5}.board>:nth-child(62){-ms-grid-row:8;-ms-grid-column:6}.board>:nth-child(63){-ms-grid-row:8;-ms-grid-column:7}.board>:nth-child(64){-ms-grid-row:8;-ms-grid-column:8}.board .grid__item{margin:auto}.board .piece:nth-child(4){-ms-grid-column:5;grid-column:5}.board .piece:nth-child(12){-ms-grid-column:6;grid-column:6}.board .piece:nth-child(20){-ms-grid-column:8;grid-column:8}.row7{-ms-grid-row:7;grid-row:7}.row8{-ms-grid-row:8;grid-row:8}[class^=move]{height:100%;width:100%}[class^=move] .piece{height:12vmin;width:12vmin;display:-webkit-box;display:-ms-flexbox;display:flex;-ms-grid-row-align:end;-ms-grid-column-align:end;place-self:end}[class^=move] span{margin:auto}.move1{-ms-grid-columns:72vmin 1fr;grid-template-columns:72vmin 1fr;-ms-grid-rows:84vmin 1fr;grid-template-rows:84vmin 1fr;-webkit-transition:grid-template-rows .5s linear;-o-transition:grid-template-rows .5s linear;transition:grid-template-rows .5s linear;transition:grid-template-rows .5s linear,-ms-grid-rows .5s linear}.move1>:nth-child(1){-ms-grid-row:1;-ms-grid-column:1}.move1>:nth-child(2){-ms-grid-row:1;-ms-grid-column:2}.move1>:nth-child(3){-ms-grid-row:2;-ms-grid-column:1}.move1>:nth-child(4){-ms-grid-row:2;-ms-grid-column:2}.move1.active{-ms-grid-rows:72vmin 1fr;grid-template-rows:72vmin 1fr}.move2{-ms-grid-columns:60vmin 1fr;grid-template-columns:60vmin 1fr;-ms-grid-rows:24vmin 1fr;grid-template-rows:24vmin 1fr;-webkit-transition:grid-template-rows .75s linear;-o-transition:grid-template-rows .75s linear;transition:grid-template-rows .75s linear;transition:grid-template-rows .75s linear,-ms-grid-rows .75s linear}.move2>:nth-child(1){-ms-grid-row:1;-ms-grid-column:1}.move2>:nth-child(2){-ms-grid-row:1;-ms-grid-column:2}.move2>:nth-child(3){-ms-grid-row:2;-ms-grid-column:1}.move2>:nth-child(4){-ms-grid-row:2;-ms-grid-column:2}.move2.active{-ms-grid-rows:48vmin 1fr;grid-template-rows:48vmin 1fr}.move3{-ms-grid-columns:84vmin 1fr;grid-template-columns:84vmin 1fr;-ms-grid-rows:84vmin 1fr;grid-template-rows:84vmin 1fr;-webkit-transition:grid-template-rows .75s linear;-o-transition:grid-template-rows .75s linear;transition:grid-template-rows .75s linear;transition:grid-template-rows .75s linear,-ms-grid-rows .75s linear}.move3>:nth-child(1){-ms-grid-row:1;-ms-grid-column:1}.move3>:nth-child(2){-ms-grid-row:1;-ms-grid-column:2}.move3>:nth-child(3){-ms-grid-row:2;-ms-grid-column:1}.move3>:nth-child(4){-ms-grid-row:2;-ms-grid-column:2}.move3.active{-ms-grid-rows:60vmin 1fr;grid-template-rows:60vmin 1fr}.move4{-ms-grid-columns:48vmin 1fr;grid-template-columns:48vmin 1fr;-ms-grid-rows:12vmin 1fr;grid-template-rows:12vmin 1fr;-webkit-transition:grid-template-columns 1.25s linear,grid-template-rows 1.25s linear;-o-transition:grid-template-columns 1.25s linear,grid-template-rows 1.25s linear;transition:grid-template-columns 1.25s linear,grid-template-rows 1.25s linear;transition:grid-template-columns 1.25s linear,grid-template-rows 1.25s linear,-ms-grid-columns 1.25s linear,-ms-grid-rows 1.25s linear}.move4>:nth-child(1){-ms-grid-row:1;-ms-grid-column:1}.move4>:nth-child(2){-ms-grid-row:1;-ms-grid-column:2}.move4>:nth-child(3){-ms-grid-row:2;-ms-grid-column:1}.move4>:nth-child(4){-ms-grid-row:2;-ms-grid-column:2}.move4.active{-ms-grid-columns:96vmin 1fr;grid-template-columns:96vmin 1fr;-ms-grid-rows:60vmin 1fr;grid-template-rows:60vmin 1fr}.move4.active>:nth-child(1){-ms-grid-row:1;-ms-grid-column:1}.move4.active>:nth-child(2){-ms-grid-row:1;-ms-grid-column:2}.move4.active>:nth-child(3){-ms-grid-row:2;-ms-grid-column:1}.move4.active>:nth-child(4){-ms-grid-row:2;-ms-grid-column:2}.controls{width:36vmin;display:-webkit-box;display:-ms-flexbox;display:flex;margin-top:1em;-ms-flex-pack:distribute;justify-content:space-around}button{font-size:initial;background-color:#d18b47;border:none;padding:.5em .75em;cursor:pointer}</style>
</head>

<body>
  <header>
    <h1>Fool's Mate</h1>
    <p>In chess, Fool's Mate, also known as the Two-Move Checkmate, is the checkmate in the fewest possible number of moves from the start of the game. This can be achieved only by Black, who can deliver checkmate on move 2 with the queen. Fool's Mate received its name because it can only occur if White commits an extraordinary blunder. Even among rank beginners, the mate almost never occurs in practice.</p>
  </header>
    
  <main>
    <div class="grid board">
      <div class="grid__item piece">♜</div>
      <div class="grid__item piece">♞</div>
      <div class="grid__item piece">♝</div>
      <div class="grid__item piece">♚</div>
      <div class="grid__item piece">♝</div>
      <div class="grid__item piece">♞</div>
      <div class="grid__item piece">♜</div>
      <div class="grid__item piece">♟</div>
      <div class="grid__item piece">♟</div>
      <div class="grid__item piece">♟</div>
      <div class="grid__item piece">♟</div>
      <div class="grid__item piece">♟</div>
      <div class="grid__item piece">♟</div>
      <div class="grid__item piece">♟</div>
      <div class="grid__item piece row7">♙</div>
      <div class="grid__item piece row7">♙</div>
      <div class="grid__item piece row7">♙</div>
      <div class="grid__item piece row7">♙</div>
      <div class="grid__item piece row7">♙</div>
      <div class="grid__item piece row7">♙</div>
      <div class="grid__item piece row8">♖</div>
      <div class="grid__item piece row8">♘</div>
      <div class="grid__item piece row8">♗</div>
      <div class="grid__item piece row8">♕</div>
      <div class="grid__item piece row8">♔</div>
      <div class="grid__item piece row8">♗</div>
      <div class="grid__item piece row8">♘</div>
      <div class="grid__item piece row8">♖</div>
    </div>
  
    <div class="move1 grid">
      <div class="piece"><span>♙</span></div>
    </div>
  
    <div class="move2 grid">
      <div class="piece"><span>♟</span></div>
    </div>
  
    <div class="move3 grid">
      <div class="piece"><span>♙</span></div>
    </div>
  
    <div class="move4 grid">
      <div class="piece"><span>♛</span></div>
    </div>
  </main>
  
  <div class="controls">
    <button type="button" id="prev">Prev</button>
    <button type="button" id="next">Next</button>
  </div>
  
  <script>"use strict";var prevBtn=document.getElementById("prev"),nextBtn=document.getElementById("next"),moves=0;function nextHandler(){moves<4?(countUp(),addActive(moves),console.log(moves)):console.log("Already checkmate")}function prevHandler(){moves>0?(removeActive(moves),countDown(),console.log(moves)):console.log("Back to the start")}function addActive(e){document.querySelector(".move"+e).classList.add("active")}function removeActive(e){document.querySelector(".move"+e).classList.remove("active")}function countUp(){return moves++}function countDown(){return moves--}prevBtn.addEventListener("click",prevHandler,!1),nextBtn.addEventListener("click",nextHandler,!1);</script>
</body>

</html>
